package com.spzx.cart.controller;

import com.spzx.cart.api.domain.CartInfo;
import com.spzx.cart.service.ICartservice;
import com.spzx.common.core.constant.SecurityConstants;
import com.spzx.common.core.domain.R;
import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.core.web.domain.AjaxResult;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/*
    并非全力
*/
@Tag(name = "购物车接口")
@RestController
@RequestMapping
public class cartController extends BaseController {

    @Autowired
    ICartservice cartservice;

    @PutMapping("/updateCartPrice")
    R<Boolean> updateCartPrice() {
        int i = cartservice.updateCartPrice();
        return R.ok();
    }

    @DeleteMapping("/removeCheckedCart")
    R<Boolean> removeCheckedCart() {
        int i = cartservice.removeCheckedCart();
        return R.ok();
    }


    @GetMapping("/clearCart")
    public AjaxResult clearCart() {
        cartservice.clearCart();
        return AjaxResult.success();
    }


    @GetMapping("/checkCart/{skuId}/{status}")
    public AjaxResult checkCart(@PathVariable Long skuId, @PathVariable Integer status) {
        cartservice.checkCart(skuId, status);
        return AjaxResult.success();
    }


    @DeleteMapping("/deleteCart/{skuId}")
    public AjaxResult deleteCart(@PathVariable Long skuId) {
        cartservice.deleteCart(skuId);
        return AjaxResult.success();
    }


    @GetMapping("addToCart/{skuId}/{skuNum}")
    public AjaxResult addToCart(@PathVariable Long skuId, @PathVariable Integer skuNum) {
        cartservice.addToCart(skuId, skuNum);
        return success();
    }

    @GetMapping("cartList")
    public AjaxResult cartList() {
        List<CartInfo> cartInfoList = cartservice.cartList();
        return success(cartInfoList);
    }
}
